package com.bujunjie.study.realtime.dws.app.function;

import com.bujunjie.study.realtime.dws.app.util.KeywordUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

/**
 * <p>关键字 UDF 函数</p>
 *
 * @author bu.junjie
 * @version 1.0.0
 * @createTime 2025/9/19 15:10
 */
@FunctionHint(output = @DataTypeHint("ROW<word STRING>"))
public class KeywordUDTF extends TableFunction<Row> {

    /**
     * <p>将文本进行分割</p>
     *
     * @param text 分割的文本
     * @return
     * @author bu.junjie
     * @date 2025/9/19 15:18
     */
    public void eval(String text) {
        for (String keyword : KeywordUtil.analyze(text)) {
            collect(Row.of(keyword));
        }
    }
}
